package com.luomo.java.juc.producerconsumer;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author LiuMei
 * @date 2021-04-13.
 */
public class BlockQueueDemo {

    public static void main(String[] args) {
        BlockQueueShareData shareData = new BlockQueueShareData(new ArrayBlockingQueue<>(3));
        new Thread(() -> {
            System.out.println("生产线程启动");
            System.out.println();
            shareData.add();
        }, "producer").start();
        new Thread(() -> {
            System.out.println("消费线程启动");
            System.out.println();
            shareData.sub();
        }, "consumer").start();
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        shareData.stop();
    }
}
